package com.example.myapplication.mine

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.example.myapplication.R
import com.example.myapplication.navigation.AppRoute
import com.example.myapplication.navigation.NavigationManager

@Composable
fun MineScreen() {
    val data = arrayOf("账号与安全","设置","关于")

    Column(modifier = Modifier.fillMaxSize().background(Color(0xFFFFFFFF))){
        NavigationBar()

        LazyColumn(modifier = Modifier.fillMaxSize().background(Color(0xFFF5F5F6)).padding(top = 20.dp)) {
            items(data.count(),key={ index -> index.toString()}){ index ->
                Row(modifier = Modifier.fillMaxWidth()
                    .height(47.dp)
                    .background(Color.White)
                    .border(width = 0.5.dp,Color(0xFFEEEEEE))
                    .clickable(enabled = true){//clickable事件需要再padding之前，这样是整个Row组件看上去都有点击效果
//                        Log.d(TAG,"item index was clicked")
                        println("item was clicked, index is ${index}")
                        //点击不同的item，切换到不同的界面
                        when (index){
                            0 -> {
                                println("账号与安全item被点击了")
                                NavigationManager.navigate(AppRoute.ACCOUNT_AND_SECURITY)
                            }
                            1 -> {
                                println("设置item被点击了")
                                NavigationManager.navigate(AppRoute.APP_SETTING)
                            }
                            2 -> {
                                println("关于item被点击了")
                                NavigationManager.navigate(AppRoute.APP_ABOUTVERSION)
                            }
                        }
                    }
                    .padding(start = 15.dp, end = 13.dp),
                    verticalAlignment = Alignment.CenterVertically,
                    horizontalArrangement = Arrangement.SpaceBetween
                ) {
                    Text(data[index])
                    Image(painter = painterResource(R.drawable.arrow_right_icon), contentDescription = "", modifier = Modifier.width(16.dp).height(16.dp))
                }
            }
        }
    }
}